// @ts-check
/**
 * API 模块：封装用户相关的后端接口调用
 */

export const API = {
  /** @param {{username:string,password:string,email:string}} payload */
  async addUser(payload) {
    return axios.post('/form', payload).then(r => r.data);
  },

  async getUsers() {
    return axios.get('/users').then(r => r.data);
  },

  /** @param {number} id @param {{username?:string,email?:string,password?:string}} payload */
  async updateUser(id, payload) {
    return axios.put(`/users/${id}`, payload).then(r => r.data);
  },

  /** @param {number} id @param {boolean} hard */
  async deleteUser(id, hard) {
    return axios.delete(`/users/${id}`, { params: { hard } }).then(r => r.data);
  }
};